<template>
  <div class="banner">
    <div class="swiper banxin">
      <!-- 轮播图 -->
      <van-swipe :autoplay="3000" ref="swiper">
        <van-swipe-item v-for="(image, index) in images" :key="index">
          <img v-lazy="image.pic" />
        </van-swipe-item>
      </van-swipe>

      <!-- 左右切换按钮-->
      <span class="btn prev" @click="prev()">&lt;</span>
      <span class="btn next" @click="next()">&gt;</span>

      <!-- 客户端下载 -->
      <div class="download">
        <span class="download_btn" @click="$router.push('/download')"></span>
        <p>PC 安卓 iPhone WP iPad Mac 六大客户端</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getBannerApi } from "@/request/api.js";
export default {
  data() {
    return {
      images: [
        "https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg",
        "https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg",
      ],
    };
  },
  created() {
    getBannerApi().then((res) => {
      // console.log(res);
      this.images = res.data.banners;
    })
  },
  methods: {
    prev() {
      this.$refs.swiper.prev();
    },
    next() {
      this.$refs.swiper.next();
    }
  },
};
</script>

<style lang = "less">
@import "../../assets/base.less";
.banner {
  background-color: #999;
  .swiper {
    display: flex;
    height: 280px;
    position: relative;
    .van-swipe {
      width: 750px;
      height: 280px;
      .van-swipe-item {
        img {
          width: 100%;
          height: 100%;
        }
      }
      .van-swipe__indicator--active {
        background-color: @red;
      }
    }

    /* 左右按钮样式 */
    .btn {
      display: block;
      position: absolute;
      width: 35px;
      line-height: 60px;
      border-radius: 5px;
      top: 50%;
      transform: translateY(-45%);
      transition: 0.5s;
      color: #ffffff;
      font-family: "黑体";
      font-size: 30px;
      font-weight: bold;
      text-align: center;
      cursor: pointer;
      /* 禁止用户选择文本 */
      user-select: none;
      &:hover {
        cursor: pointer;
        width: 35px;
        line-height: 60px;
        background-color: rgba(0, 0, 0, 0.2);
      }
    }
    .prev .next {
      color: #ffffff;
    }
    .prev {
      left: -50px;
    }
    .next {
      right: -50px;
    }

    /* 右边样式 */
    .download {
      position: relative;
      width: 250px;
      height: 280px;
      display: block;
      background: url("@/assets/images/public/download.png") no-repeat;
      background-position: 0 0;
      .download_btn {
        position: absolute;
        left: 19px;
        top: 185px;
        width: 215px;
        height: 56px;
        display: block;
        background: url("@/assets/images/public/download.png") no-repeat;
        background-position: -19px -185px;
        &:hover {
          cursor: pointer;
          background-position: 0 -289px;
        }
      }
      p {
        position: absolute;
        left: 0;
        bottom: 0;
        height: 20px;
        width: 250px;
        color: #8d8d8d;
        font-size: 12px;
        line-height: 20px;
        text-align: center;
        margin: 10px auto;
      }
    }
  }
}
</style>